package github._3y.concurrency;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Auther DRevelation
 * @Date 2020-05-27 下午 15:24
 * @Desc
 */
public class CountDownLatchDemo {
    public static void main(String[] args) {
        ExecutorService exec = Executors.newFixedThreadPool(5);
        CountDownLatch countDownLatch = new CountDownLatch(5);
        System.out.println("现在6点下班了...");

        exec.submit(() -> {
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("其他员工走完了，3y终于可以走了...");
        });

        for (int i = 0; i < 5; i++) {
            int finalI = i;
            exec.submit(() -> {
                System.out.println("员工【" + finalI + "】下班了");
                countDownLatch.countDown();
            });
        }
    }
}
